import request from "@/axios/request";
import { defineStore } from "pinia";
import { store } from "./store";

export const useDynamicFormDesignStore = defineStore(
  "dynamicFormDesign",
  () => {
    function create(data) {
      return request.post({
        url: "/api/FormDesign/Create",
        data: data,
      });
    }
    function update(data) {
      return request.put({
        url: "/api/FormDesign/Update",
        data: data,
      });
    }
    function addOrUpdate(data) {
      return request.put({
        url: "/api/FormDesign/AddOrUpdate",
        data: data,
      });
    }
    function get(params) {
      return request.get({
        url: "/api/FormDesign/Get",
        params: params,
      });
    }
    function getFormDesignVersion(params) {
      return request.get({
        url: "/api/FormDesign/GetFormDesignVersion",
        params: params,
      });
    }
    function Delete(params) {
      return request.delete({
        url: "/api/FormDesign/Delete",
        params: params,
      });
    }
    function getAllFormDesignVersions(params) {
      return request.get({
        url: "/api/FormDesign/getAllFormDesignVersions",
        params: params,
      });
    }
    function getAllFormDesignVersionsByWorkflowId(params) {
      return request.get({
        url: "/api/FormDesign/GetAllFormDesignVersionsByWorkflowId",
        params: params,
      });
    }
    function getAllList(params) {
      return request.get({
        url: "/api/FormDesign/getAllList",
        params: params,
      });
    }
    function setActiveVersion(data) {
      return request.put({
        url: "/api/FormDesign/SetActiveVersion",
        data: data,
        params: {
          id: data.id,
        },
      });
    }
    function getPageList(params) {
      return request.get({
        url: "/api/FormDesign/GetPageList",
        params: params,
      });
    }
    function getFormDesignVersionByWorkflowId(params) {
      return request.get({
        url: "/api/FormDesign/GetFormDesignVersionByWorkflowId",
        params: params,
      });
    }
    function getFormDesignVersionByWorkTaskId(params) {
      return request.get({
        url: "/api/FormDesign/GetFormDesignVersionByWorkTaskId",
        params: params,
      });
    }

    function getActiveFormDesignVersionByWorkflowId(params) {
      return request.get({
        url: "/api/FormDesign/GetActiveFormDesignVersionByWorkflowId",
        method: "get",
        params: params,
      });
    }

    function getFormDesignVersionByWorkflowIdAndVersion(params) {
      return request.post({
        url: "/api/FormDesign/GetFormDesignVersionByWorkflowIdAndVersion",
        method: "get",
        params: params,
      });
    }

    return {
      create,
      update,
      addOrUpdate,
      get,
      getFormDesignVersion,
      Delete,
      getAllFormDesignVersions,
      getAllFormDesignVersionsByWorkflowId,
      getAllList,
      setActiveVersion,
      getPageList,
      getFormDesignVersionByWorkflowId,
      getFormDesignVersionByWorkTaskId,
      getActiveFormDesignVersionByWorkflowId,
      getFormDesignVersionByWorkflowIdAndVersion,
    };
  }
);

export const useDynamicFormDesignStoreWithOut = () => {
  return useDynamicFormDesignStore(store);
};
